import os
import sys
import django
from django.utils import timezone

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'taskmanager.settings')
django.setup()

from tasks.models import Task, TaskLog


import random
from faker import Faker

fake = Faker('zh_CN')

TASK_TYPES = ['开发', '测试', '文档', '设计', '运维']
STATUSES = ['未开始', '进行中', '已完成', '已暂停']
HIGHLIGHTS = ['高优先级', '中优先级', '低优先级']


def create_fake_data():
    for i in range(1, 51):
        # 创建任务日志
        log_count = random.randint(1, 3)
        logs = []
        for j in range(log_count):
            log = TaskLog.objects.create(
                date=fake.date_between(start_date='-1y', end_date='today'),
                time=fake.time(),
                content=fake.sentence(),
                next_action=fake.sentence()
            )
            logs.append(log)

        # 创建任务
        Task.objects.create(
            task_type=random.choice(TASK_TYPES),
            task_id=f'{random.choice(TASK_TYPES[:3])}{i:03d}',
            task_title=fake.sentence(),
            assignee=fake.name(),
            status=random.choice(STATUSES),
            highlight=random.choice(HIGHLIGHTS),
            dev_comment=fake.paragraph(),
            next_action=fake.sentence()
        ).logs.set(logs)

if __name__ == '__main__':
    create_fake_data()
    print('假数据创建完成！')